function e(e, t, i) {
    return t in e ? Object.defineProperty(e, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = i, e;
}

function t(e, t) {
    if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}

function i() {}

function r(e, t, i) {
    var r = !0;
    if (e) {
        var s = 0, n = e.length, o = t[0], a = t[1], f = t[2];
        switch (t.length) {
          case 0:
            for (;s < n; s += 2) r = !1 !== e[s].call(e[s + 1] || i) && r;
            break;

          case 1:
            for (;s < n; s += 2) r = !1 !== e[s].call(e[s + 1] || i, o) && r;
            break;

          case 2:
            for (;s < n; s += 2) r = !1 !== e[s].call(e[s + 1] || i, o, a) && r;
            break;

          case 3:
            for (;s < n; s += 2) r = !1 !== e[s].call(e[s + 1] || i, o, a, f) && r;
            break;

          default:
            for (;s < n; s += 2) r = !1 !== e[s].apply(e[s + 1] || i, t) && r;
        }
    }
    return r;
}

function s(e) {
    return "[object Function]" === Object.prototype.toString.call(e);
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var n = function() {
    function e(e, t) {
        for (var i = 0; i < t.length; i++) {
            var r = t[i];
            r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), 
            Object.defineProperty(e, r.key, r);
        }
    }
    return function(t, i, r) {
        return i && e(t.prototype, i), r && e(t, r), t;
    };
}(), o = /\s+/;

i.prototype.on = function(e, t, i) {
    var r, s;
    if (!t) return this;
    for (r = this.__events || (this.__events = {}), e = e.split(o); s = e.shift(); ) (r[s] || (r[s] = [])).push(t, i);
    return this;
}, i.prototype.once = function(e, t, i) {
    var r = this;
    return this.on(e, function s() {
        r.off(e, s), t.apply(i || r, arguments);
    }, i);
}, i.prototype.off = function(e, t, i) {
    var r, s, n, f;
    if (!(r = this.__events)) return this;
    if (!(e || t || i)) return delete this.__events, this;
    for (e = e ? e.split(o) : a(r); s = e.shift(); ) if (n = r[s]) if (t || i) for (f = n.length - 2; f >= 0; f -= 2) t && n[f] !== t || i && n[f + 1] !== i || n.splice(f, 2); else delete r[s];
    return this;
}, i.prototype.trigger = function(e) {
    var t, i, s, n, a, f, h = [], u = !0;
    if (!(t = this.__events)) return this;
    for (e = e.split(o), a = 1, f = arguments.length; a < f; a++) h[a - 1] = arguments[a];
    for (;i = e.shift(); ) (s = t.all) && (s = s.slice()), (n = t[i]) && (n = n.slice()), 
    "all" !== i && (u = r(n, h, this) && u), u = r(s, [ i ].concat(h), this) && u;
    return u;
}, i.prototype.emit = i.prototype.trigger;

var a = Object.keys;

a || (a = function(e) {
    var t = [];
    for (var i in e) e.hasOwnProperty(i) && t.push(i);
    return t;
}), i.mixTo = function(e) {
    var t = i.prototype;
    if (s(e)) for (var r in t) t.hasOwnProperty(r) && (e.prototype[r] = t[r]); else {
        var n = new i();
        for (var r in t) t.hasOwnProperty(r) && function(i) {
            e[i] = function() {
                return t[i].apply(n, Array.prototype.slice.call(arguments)), this;
            };
        }(r);
    }
};

var f = function() {
    function r() {
        var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : getCurrentPages()[getCurrentPages().length - 1];
        t(this, r), Object.assign(this, {
            options: e,
            scope: i
        }), this.__init();
    }
    return n(r, [ {
        key: "__init",
        value: function() {
            this.lastTime = 0, this.activated = !1, this.events = new i(), this.mergeOptions(this.options), 
            this.scope.setData(e({}, "$wux.refresher", this.options));
        }
    }, {
        key: "setDefaults",
        value: function() {
            return {
                pullingIcon: "wux-refresher__icon--arrow-down",
                pullingText: "下拉刷新",
                refreshingIcon: "wux-refresher__icon--refresher",
                refreshingText: "正在刷新",
                disablePullingRotation: !1,
                distance: 30,
                onPulling: function() {},
                onRefresh: function() {}
            };
        }
    }, {
        key: "mergeOptions",
        value: function(e) {
            var t = this.setDefaults();
            for (var i in t) t.hasOwnProperty(i) && (this.options[i] = void 0 !== e[i] ? e[i] : t[i], 
            "function" == typeof this.options[i] && (this.options[i] = this.options[i].bind(this)));
        }
    }, {
        key: "requestAnimationFrame",
        value: function(e) {
            var t = this, i = new Date().getTime(), r = Math.max(0, 16 - (i - this.lastTime)), s = setTimeout(function() {
                e.bind(t)(i + r);
            }, r);
            return this.lastTime = i + r, s;
        }
    }, {
        key: "cancelAnimationFrame",
        value: function(e) {
            clearTimeout(e);
        }
    }, {
        key: "getRefresherMethods",
        value: function() {
            var t = this, i = "transition: transform .4s; transform: translate3d(0px, 0px, 0px) scale(1);", r = function(i, r) {
                t.scope.setData(e({}, "$wux.refresher." + i, r));
            };
            return {
                setData: r,
                activate: function() {
                    r("style", i), r("className", "wux-refresher--visible");
                },
                deactivate: function() {
                    t.activated && (t.activated = !1), r("style", i), r("className", "wux-refresher--hidden");
                },
                refreshing: function() {
                    r("style", "transition: transform .4s; transform: translate3d(0, 50px, 0) scale(1);"), 
                    r("className", "wux-refresher--active wux-refresher--refreshing");
                },
                tail: function() {
                    r("className", "wux-refresher--active wux-refresher--refreshing wux-refresher--refreshing-tail");
                },
                move: function(e) {
                    r("style", "transition-duration: 0s; transform: translate3d(0, " + e + "px, 0) scale(1);"), 
                    r("className", e < t.options.distance ? "wux-refresher--visible" : "wux-refresher--active");
                }
            };
        }
    }, {
        key: "refreshing",
        value: function() {
            return -1 !== (this.scope.data.$wux.refresher.className || "").indexOf("wux-refresher--refreshing");
        }
    }, {
        key: "getTouchPosition",
        value: function(e) {
            return {
                x: e.changedTouches[0].pageX,
                y: e.changedTouches[0].pageY
            };
        }
    }, {
        key: "finishPullToRefresh",
        value: function() {
            var e = this, t = this.getRefresherMethods();
            setTimeout(function() {
                e.requestAnimationFrame(t.tail), setTimeout(t.deactivate, 200);
            }, 200);
        }
    }, {
        key: "touchstart",
        value: function(e) {
            if (this.refreshing()) return !1;
            var t = this.getRefresherMethods(), i = this.getTouchPosition(e);
            this.start = i, this.diffX = this.diffY = 0, t.activate();
        }
    }, {
        key: "touchmove",
        value: function(e) {
            if (!this.start || this.refreshing()) return !1;
            var t = this.getRefresherMethods(), i = this.getTouchPosition(e);
            if (this.diffX = i.x - this.start.x, this.diffY = i.y - this.start.y, this.diffY < 0) return !1;
            this.diffY = Math.pow(this.diffY, .8), !this.activated && this.diffY > this.options.distance ? (this.activated = !0, 
            "function" == typeof this.options.onPulling && this.options.onPulling()) : this.activated && this.diffY < this.options.distance && (this.activated = !1), 
            t.move(this.diffY);
        }
    }, {
        key: "touchend",
        value: function(e) {
            var t = this.getRefresherMethods();
            if (this.start = !1, this.diffY <= 0 || this.refreshing()) return !1;
            t.deactivate(), Math.abs(this.diffY) >= this.options.distance && (this.events.once("scroll.refreshComplete", this.finishPullToRefresh.bind(this)), 
            t.refreshing(), "function" == typeof this.options.onRefresh && this.options.onRefresh());
        }
    } ]), r;
}();

exports.default = f;